home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / DATETIME / UNIXTM / DT2UT.PAS < prev    next >
Pascal/Delphi Source File  |  1996-05-16  |  3KB  |  66 lines

  1. {------------------------------------------------------------------------------}
  2. {- Program    : DT2UTIME.PAS                                                  -}
  3. {- Programmer : Todd Fiske                                                    -}
  4. {-                                                                            -}
  5. {- Purpose    : Convert date and time to a unix number of seconds             -}
  6. {-                                                                            -}
  7. {- Revision   : 02/17/1994 - first version                                    -}
  8. {- History      01/16/1995 - cleaned up for uploading                         -}
  9. {-                                                                            -}
  10. {- Language   : Turbo Pascal 7.0                                              -}
  11. {-                                                                            -}
  12. {------------------------------------------------------------------------------}
  13. program dt2utime;
  14.  
  15. uses
  16.    dos,
  17.    unixtime;
  18.  
  19. var
  20.    t : longint;
  21.    d : DateTime;
  22.  
  23. {------------------------------------------------------------------------------}
  24. {- Date and time to seconds test                                              -}
  25. {------------------------------------------------------------------------------}
  26. begin
  27.    writeln;
  28.    writeln('DT 2 UnixTime');
  29.  
  30.    if paramcount = 0 then begin
  31.       writeln;
  32.       writeln('dt2utime <mm/dd/[cc]yy> [<hh:mm:ss>]');
  33.       halt;
  34.    end;
  35.  
  36.    writeln;
  37.    writeln('Packing Unix time longint');
  38.  
  39.    d.year  := str2int( copy(paramstr(1), 7, 4) );
  40.    d.month := str2int( copy(paramstr(1), 1, 2) );
  41.    d.day   := str2int( copy(paramstr(1), 4, 2) );
  42.  
  43.    d.hour  := str2int( copy(paramstr(2), 1, 2) );
  44.    d.min   := str2int( copy(paramstr(2), 4, 2) );
  45.    d.sec   := str2int( copy(paramstr(2), 7, 2) );
  46.  
  47.    if d.year < 100 then begin                    { if century not specified }
  48.       if d.year < 50 then                        { if low decade }
  49.          inc(d.year, 2000)                       { assume next century }
  50.       else
  51.          inc(d.year, 1900);                      { else assume this century }
  52.    end;
  53.  
  54.    writeln;
  55.    writeln('year      : ', d.year  : 4);
  56.    writeln('month     : ', d.month : 4);
  57.    writeln('day       : ', d.day   : 4);
  58.    writeln('hour      : ', d.hour  : 4);
  59.    writeln('minute    : ', d.min   : 4);
  60.    writeln('second    : ', d.sec   : 4);
  61.  
  62.    writeln;
  63.    PackUnixTime(d, t);
  64.    writeln('repacked  : ', t);
  65. end.
  66.